package com.ruoyi.cs.event.customeroffer.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cs.event.customeroffer.domain.CustomerOffer;
import com.ruoyi.cs.event.customeroffer.service.ICustomerOfferService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 客户报价
 * @author Drj 2021/6/28
 */
@RestController
@RequestMapping("/cs/customeroffer")
@Api(value = "客户报价模块", tags = "客户报价接口")
public class CustomerOfferController extends BaseController {
    @Autowired
    private ICustomerOfferService customerOfferService;

    /**
     * 获取客户报价
     * @param customerOffer
     * @return
     */
    @ApiOperationSupport(includeParameters = {"CustomerOffer.customerInfoId", "CustomerOffer.customerQuotaId", "CustomerOffer.offerTime"})
    @ApiOperation(value = "获取客户报价列表",notes = "查询所有客户报价")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CustomerOffer customerOffer) {
        startPage();

        List<CustomerOffer> customerOffers = customerOfferService.selectCustomerOfferList(customerOffer);
        return getDataTable(customerOffers);
    }

    /**
     * 导出客户报价
     *
     * @param customerOffer
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody CustomerOffer customerOffer) {
        List<CustomerOffer> List = customerOfferService.selectCustomerOfferList(customerOffer);
        ExcelUtil<CustomerOffer> util = new ExcelUtil<CustomerOffer>(CustomerOffer.class);
        return util.exportExcel(List, "客户报价单数据");
    }

    /**
     * 新增客户报价
     * @param customerOffer 客户报价单据
     * @return
     */
    @ApiOperation(value = "新增客户报价", notes = "新增客户报价")
    @ApiImplicitParam(name = "customerOffer", value = "新增客户报价", dataType = "CustomerOffer")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CustomerOffer customerOffer) {
        try {
            return toAjax(customerOfferService.insertCustomerOffer(customerOffer));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("新增失败");
        }
    }

    /**
     *
     * 更新客户报价
     * @param customerOffer 客户报价单据
     * @return
     */
    @ApiOperation(value = "更新客户报价", notes = "更新客户报价")
    @ApiImplicitParam(name = "customerOffer", value = "更新客户报价", dataType = "CustomerOffer")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody CustomerOffer customerOffer) {
        try {
            return toAjax(customerOfferService.updateCustomerOffer(customerOffer));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("修改失败");
        }
    }

    /**
     * 删除客户报价
     * 仅修改删除标志位
     *
     * @param customerOffer 客户报价单据
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody CustomerOffer customerOffer) {

        return toAjax(customerOfferService.updateCustomerOfferDeleteFlag(customerOffer));
    }
}
